import { RECEIVE_HOT_SONGS } from "./types";
import { getHotBang, getSongDetail } from "../../../api/summary";
import { createSong } from "../../../assets/js/songModel";
const receiveHotSongs = data => ({ type: RECEIVE_HOT_SONGS, data });

export const getHotSongsAction = idx => async dispatch => {
  try {
    const result = await getHotBang(idx);
    const ids = result.playlist.trackIds.map(item => item.id).slice(0, 20);
    let details = await getSongDetail(ids.join(","));
    details = details.songs.map(item => {
      return createSong(item);
    });
    dispatch(receiveHotSongs(details));
  } catch (error) {
    console.log(error);
  }
};
